<?php include_once '../PlantillasUI/_MainLayout.php'; ?>
<?php include_once '../Model/OrdenDao.php';?>
<div id="wrapper">
    <div class="row">
        <div class="col-md-3 col-md-2"></div>
        <div class="col-xs-12 col-sm-8">
            <h1>Monthly history</h1>
            <button type="button" class="btn btn-success" id="new">New purchase order</button>
        </div>
        <div class="col-xs-3 col-sm-2"></div>
    </div>
    <br/>
    <div class="row">
        <div class="col-md-2"></div>
        <div class="col-xs-12 col-sm-12 col-md-8">
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <tr>
                        <th>Orden #</th>
                        <th>Total amount</th>
                        <th>Creation date</th>
                        <th>State</th>
                        <?php
                            if(strcmp($rol,'PRO') != 0) {
                        ?>
                            <th>Creation user</th>
                            <th>Piority</th>
                        <?php
                            }
                        ?>
                    </tr>
                    <?php
                    $results = adminOrden($user,'COM');
                    $cant = count($results);
                    for ($i = 0; $i < $cant; $i++) {
                        echo '<tr class="data" id="' . $results[$i]['idOrden'] . '" step="' . $results[$i]['stepCode'] . '">';
                        echo '<td><a href="OrdenCompraDet.php?idOrden=' . $results[$i]['idOrden'] . '">' . $results[$i]['idOrden'] . '</a></td>';
                        echo '<td>' . $results[$i]['total'] . '</td>';
                        $dateC = date_create($results[$i]['creationDate']);
                        echo '<td>' . date_format($dateC, 'd/m/y') . '</td>';
                        echo '<td>' . $results[$i]['stepName'] . '</td>';
                        if(strcmp($rol,'PRO') != 0) {
                            echo '<td>' . $results[$i]['creationUser'] . '</td>';
                            echo '<td>'.$results[$i]['idPrioridad'].'<span class="glyphicon ' . $results[$i]['icono'] . '" aria-hidden="true"></span></td>';
                        }
                        echo '</tr>';
                    }
                    ?>
                </table>
            </div>

        </div>
        <div class="col-md-2"></div>
    </div>
</div>

<script type="text/javascript">
    $('#new').click(function (){
        window.location = 'OrdenCompraDet.php?idOrden=0';
    });
    $('.data').click(function() {
        if($(this).attr('step')!=='DND'){
           window.location = 'OrdenCompraDet.php?idOrden=' + $(this).attr('id')+'&s='+$(this).attr('step');
        }
    });
    $('.data').css( 'cursor', 'pointer' );
</script>
<?php include_once '../PlantillasUI/_footerLayout.php'; ?>
